<%@ page language="java" import="java.util.*,ms.platform.system.model.*"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<title>添加用户</title>
<base href="<%=basePath%>">
<link rel="stylesheet" type="text/css" href="<%=basePath%>js/bootstrap-3.3.6/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/bootstrapValidator.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/mydialog.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/style.css" />
<script type="text/javascript" src="<%=basePath%>js/validate/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/bootstrap-3.3.6/dist/js/bootstrap.min.js" charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath%>js/validate/bootstrapValidator.js"></script>
<script type="text/javascript" src="<%=basePath%>js/validate/zh_CN.js"></script>
<script type="text/javascript"
	src="<%=basePath%>js/common/dialog.3.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/rem.js"
	charset="utf-8"></script>
<script type="text/javascript">
	$(function() {
		$("input[name='username']").val(" ");
		setTimeout(function() {
			$("input[name='username']").val("");
			$("input[name='password']").val(""); 
		},100)
	})
</script>
</head>
<body>
	<div id="index-hav2">
		<div class="index-hav-right" id="index-hav-right-clear">
			<div class="row">
				<div class="col-md-9">
					<span id="icon-house"> </span><span id="arrows-left">首页</span> 
					<span id="arrows-left">></span><span>系统管理</span> 
					<span id="arrows-left">></span><span>用户管理</span>
				</div>
				<div class="bank-box">
					<div class="lianlian platform">
						<div class="col-md-12" style="margin: 13px 0">
							<form id="defaultForm" method="post" class="form-horizontal"
								action="<%=path%>/system/admin/save" autocomplete="wx">

								<div class="form-group"
									style="margin-top: 0.1rem; margin-bottom: 0.1rem;">
									<label class="col-sm-2 control-label">姓名:</label>
									<div class="col-sm-6">
										<input type="text" autocomplete="off" name="username" class="form-control"
											value="" autocomplete="wx">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-2 control-label">密码:</label>
									<div class="col-sm-6">
										<input type="password"  name="password" class="form-control" id="password"
											value="" autocomplete="wx">
									</div>
								</div>
								
								<div class="form-group">
									<label class="col-sm-2 control-label">确认密码:</label>
									<div class="col-sm-6">
										<input type="password" name="confirmPassword" class="form-control" id="confirmPassword"
											value="" autocomplete="wx">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-2 control-label">座机:</label>
									<div class="col-sm-6">
										<input type="text" name="mobile" class="form-control" value="">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-2 control-label">手机:</label>
									<div class="col-sm-6">
										<input type="text" name="phone" class="form-control" value="">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-2 control-label">邮箱:</label>
									<div class="col-sm-6">
										<input type="text" name="email" class="form-control" value="">
									</div>
								</div>
								
								<div class="form-group">
									<label class="col-sm-2 control-label">所属组织:</label>
									<div class="col-sm-6">
										<select class=" form-control input-sm" name="orgId" id="orgId">
											<c:if test="${not empty factory}">
												<c:forEach items="${factory }" var="factory" varStatus="m">
													<option value = "${factory.orgCode }">${factory.orgName}</option>
												</c:forEach>
											</c:if>
										</select>
									</div>
								</div>
								
								<div class="form-group">
									<label class="col-sm-2 control-label">状态:</label>
									<div class="col-sm-6">
										<select class="form-control input-sm mb15" name="isUsed">
											<option value="">请选择</option>
											<option value="0">禁用 </option> 
											<option value="1">启用 </option>
										</select>
									</div>
									<div class="col-sm-8 col-btn-12">
										<button type="submit" class="btn btn-primary">保存</button>
										<!-- button type="button" class="clearForm btn btn-default">重置</button -->
										<button type="button" class="btn btn-default"
											onclick="window.location.href='<%=path%>/bus/meter/returnMeterGive?url=<%=path%>/system/admin/list&flg=adminListByCondition'">返回</button>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div id="gray-screen"></div>
</body>

<script type="text/javascript">
	$(document).ready(function() {
    $('#defaultForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                username: {
                    validators: {
                        notEmpty: {},
                        stringLength: {min: 3,max: 20,},
                        remote: {
                            type: 'POST',
                        	url: '<%=path%>/system/admin/getUserByName',
							message : '该用户名已存在,不可用',
							delay : 1000
						},
				regexp : {
					regexp : /^[a-zA-Z0-9_\.]+$/,
					message : '用户名只能由字母、数字、数字和下划线组成'
				}
					}
				},
				email : {
					validators : {
						notEmpty : {},
						emailAddress : {}
					}
				},
				password : {
					validators : {
					    notEmpty : {},
			               /*  different: {
			                        field: 'username',
			                        message: '密码不能和用户名一致'
						       }, */
					   /*  stringLength: {
			                        min: 3,
			                        max: 15,
			                        message: '密码长度不得小于3位不得大于15位'
			                    }	 */       
			                    regexp : {
			    					regexp : /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[\~\!\@\#\$\%\^\&\*\'\"\[\]\_\+\-\=\\\|\{\}\:\;\,\.\/\?\<\>])[\da-zA-Z\~\!\@\#\$\%\^\&\*\'\"\[\]\_\+\-\=\\\|\{\}\:\;\,\.\/\?\<\>]{8,16}$/,
			    					message : '密码设置必须满足长度8位及以上，数字+字母+特殊字符 组合'
			    				},
						      
					}
				},
				confirmPassword : {
					validators : {
						 notEmpty : {},
						 identical: {
				                        field: 'password',
				                        message: '两次密码不一致'
								}
				            /* ,  different: {
				                        field: 'username',
				                        message: '密码不能和用户名一致'
							      } */
					}
				},
				mobile: {
					validators : {
						//notEmpty : {},
						stringLength : {
							min : 7,
							max : 13,
							message : '请输入7到13位座机号码'
						},
						regexp : {
							regexp :  "([0-9]{3,4}-)?[0-9]{7,8}",
							message : '请输入正确的座机号码'
						}
					}
				},
				phone : {
					validators : {
						notEmpty : {},
						stringLength : {
							min : 11,
							max : 11,
							message : '请输入11位手机号码'
						},
						remote: {
		                       	 	type: 'POST',
		                    		url: '<%=path%>/system/admin/validateByPhone',
							message : '该手机号码已被注册',
							delay : 1000
							},
						regexp : {
							regexp : /^1[3|5|7|8]{1}[0-9]{9}$/, 
							message : '请输入正确的手机号码'
						}
					}
				},
				companyCode : {
					validators : {
						notEmpty : {}
					}
				},
				isUsed : {
					validators : {
						notEmpty : {}
					}
				},
			}
		}).on(
			'success.form.bv',
			function(e) {
				// Prevent form submission
				e.preventDefault();

				// Get the form instance
				var $form = $(e.target);

				// Get the BootstrapValidator instance
				var bv = $form.data('bootstrapValidator');

				// Use Ajax to submit form data
				if($("#password").val()==$("#confirmPassword").val())
				{
				$.post(
					$form.attr('action'),
					$form.serialize(),
					function(result) {
						var grayScreen = document.getElementById("gray-screen");
						Dialog({"msg" : '<div class="D_alert">'
									+ result.message
									+ '</div>',
							"title" : "提示",
							"showButtons" : true,
							"cancelButton" : false,
							"onComplete" : function() {
								$("body").empty();
								grayScreen.style.display = "none";
								window.location.href='<%=path%>/system/admin/list';
							}
						});
					}, 'json');
				}else{
					 showMessage("两次密码不一致!");
				}				
			}
			);
    
			});
</script>
</html>